package com.educationx;

import android.app.IntentService;
import android.content.Intent;
import android.os.Message;
import android.os.Messenger;
import android.os.RemoteException;

import com.restwscall.RequestMethod;
import com.restwscall.RestClient;

public class EnrollService extends IntentService {
	public EnrollService() {
		super("EnrollService");
	}

	@Override
	protected void onHandleIntent(Intent intent) {
		RestClient client = new RestClient("http://swe.cmpe.boun.edu.tr:8080/EducationX/mobile/enrollcourse");
		client.AddParam("userID", intent.getExtras().getString("userID").trim());
		client.AddParam("courseID", intent.getExtras().getString("courseID").trim());
		
		Messenger messenger = (Messenger) intent.getExtras().get("messenger");
		Message message = Message.obtain();
		
		try {
		    client.Execute(RequestMethod.POST);
		} catch (Exception e) {
		    e.printStackTrace();
		}

		String response = client.getResponse();
		
		message.obj = response;
		message.arg1 = Services.ENROLL;
		
		try {
			messenger.send(message);
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
